import { login, getUserInfo } from './api/user'
App({
    onShow() {
      wx.login({
        success: (res)=>{
          Login(res.code)
        //   获取用户信息并存储到本地
          // wx.getUserInfo({
          //   success: (res)=>{
          //       const {avatarUrl, nickName} = res.userInfo
          //       wx.setStorageSync('userInfo', {avatarUrl, nickName})
          //   }
          // })
        }
      })
    },
    
});
async function Login(code){
  // 获取用户信息
  const res = await login({"code": code})
  wx.setStorageSync('token', res.data.data.token)
  if(res.data.data.token){
    const { data: info } = await getUserInfo()
    const { avatar, nickName } = info.data
    wx.setStorageSync('userInfo', {avatar, nickName})
  } 
}